<?php
require_once 'db.class.php';

class Control{
	protected $acao;
	protected $pagina;
	protected $exec;
	protected $class;	
	protected $parametros;
	public $result;
	
	function __construct($acao,$pagina,$parametros) {
		require_once 		strtolower($pagina).'.class.php';
		
		$this->acao 		= $acao;
		$this->pagina 		= $pagina;
		$this->parametros 	= $parametros;
		$this->class 		= $this->pagina.'Control';
		$this->exec 		= $this->acao.ucfirst($this->pagina);		
	}	

	public static function arrayUtf8_converter($array){
	    array_walk_recursive($array, function(&$item, $key){
	        if(!mb_detect_encoding($item, 'utf-8', true)){
				$item = utf8_encode($item);
	        }
	    });
	    return $array;
	}

	public function Execute(){
		try {
			$this->result = new $this->class();
			$met = $this->exec;
			$this->result->$met($this->parametros);
		} catch (Exception $e) {
			echo 'Erro: ',  $e->getMessage();
		}
	}	
}
?>